<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Uniform Distribution</title>
<link rel="stylesheet" href="../../../math.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../../../index.html" title="Math Toolkit 3.3.0">
<link rel="up" href="../dists.html" title="Distributions">
<link rel="prev" href="triangular_dist.html" title="Triangular Distribution">
<link rel="next" href="weibull_dist.html" title="Weibull Distribution">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="triangular_dist.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../dists.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="weibull_dist.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="math_toolkit.dist_ref.dists.uniform_dist"></a><a class="link" href="uniform_dist.html" title="Uniform Distribution">Uniform Distribution</a>
</h4></div></div></div>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">math</span><span class="special">/</span><span class="identifier">distributions</span><span class="special">/</span><span class="identifier">uniform</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></pre>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">math</span><span class="special">{</span>
 <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">RealType</span> <span class="special">=</span> <span class="keyword">double</span><span class="special">,</span>
           <span class="keyword">class</span> <a class="link" href="../../../policy.html" title="Chapter 21. Policies: Controlling Precision, Error Handling etc">Policy</a>   <span class="special">=</span> <a class="link" href="../../pol_ref/pol_ref_ref.html" title="Policy Class Reference">policies::policy&lt;&gt;</a> <span class="special">&gt;</span>
 <span class="keyword">class</span> <span class="identifier">uniform_distribution</span><span class="special">;</span>

 <span class="keyword">typedef</span> <span class="identifier">uniform_distribution</span><span class="special">&lt;&gt;</span> <span class="identifier">uniform</span><span class="special">;</span>

 <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">RealType</span><span class="special">,</span> <span class="keyword">class</span> <a class="link" href="../../../policy.html" title="Chapter 21. Policies: Controlling Precision, Error Handling etc">Policy</a><span class="special">&gt;</span>
 <span class="keyword">class</span> <span class="identifier">uniform_distribution</span>
 <span class="special">{</span>
 <span class="keyword">public</span><span class="special">:</span>
    <span class="keyword">typedef</span> <span class="identifier">RealType</span> <span class="identifier">value_type</span><span class="special">;</span>

    <span class="identifier">uniform_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">lower</span> <span class="special">=</span> <span class="number">0</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">upper</span> <span class="special">=</span> <span class="number">1</span><span class="special">);</span> <span class="comment">// Constructor.</span>
       <span class="special">:</span> <span class="identifier">m_lower</span><span class="special">(</span><span class="identifier">lower</span><span class="special">),</span> <span class="identifier">m_upper</span><span class="special">(</span><span class="identifier">upper</span><span class="special">)</span> <span class="comment">// Default is standard uniform distribution.</span>
    <span class="comment">// Accessor functions.</span>
    <span class="identifier">RealType</span> <span class="identifier">lower</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
    <span class="identifier">RealType</span> <span class="identifier">upper</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
 <span class="special">};</span> <span class="comment">// class uniform_distribution</span>

<span class="special">}}</span> <span class="comment">// namespaces</span>
</pre>
<p>
          The uniform distribution, also known as a rectangular distribution, is
          a probability distribution that has constant probability.
        </p>
<p>
          The <a href="http://en.wikipedia.org/wiki/Uniform_distribution_%28continuous%29" target="_top">continuous
          uniform distribution</a> is a distribution with the <a href="http://en.wikipedia.org/wiki/Probability_density_function" target="_top">probability
          density function</a>:
        </p>
<div class="blockquote"><blockquote class="blockquote"><p>
            <span class="serif_italic">f(x) =1 / (upper - lower)   for lower &lt;
            x &lt; upper</span>
          </p></blockquote></div>
<div class="blockquote"><blockquote class="blockquote"><p>
            <span class="serif_italic">f(x) =zero   for x &lt; lower or x &gt; upper</span>
          </p></blockquote></div>
<p>
          and in this implementation:
        </p>
<div class="blockquote"><blockquote class="blockquote"><p>
            <span class="serif_italic">1 / (upper - lower)   for x = lower or x =
            upper</span>
          </p></blockquote></div>
<p>
          The choice of <span class="emphasis"><em>x = lower</em></span> or <span class="emphasis"><em>x = upper</em></span>
          is made because statistical use of this distribution judged is most likely:
          the method of maximum likelihood uses this definition.
        </p>
<p>
          There is also a <a href="http://en.wikipedia.org/wiki/Discrete_uniform_distribution" target="_top"><span class="bold"><strong>discrete</strong></span> uniform distribution</a>.
        </p>
<p>
          Parameters lower and upper can be any finite value.
        </p>
<p>
          The <a href="http://en.wikipedia.org/wiki/Random_variate" target="_top">random variate</a>
          <span class="emphasis"><em>x</em></span> must also be finite, and is supported <span class="emphasis"><em>lower
          &lt;= x &lt;= upper</em></span>.
        </p>
<p>
          The lower parameter is also called the <a href="http://www.itl.nist.gov/div898/handbook/eda/section3/eda364.htm" target="_top">location
          parameter</a>, <a href="http://en.wikipedia.org/wiki/Location_parameter" target="_top">that
          is where the origin of a plot will lie</a>, and (upper - lower) is
          also called the <a href="http://en.wikipedia.org/wiki/Scale_parameter" target="_top">scale
          parameter</a>.
        </p>
<p>
          The following graph illustrates how the <a href="http://en.wikipedia.org/wiki/Probability_density_function" target="_top">probability
          density function PDF</a> varies with the shape parameter:
        </p>
<div class="blockquote"><blockquote class="blockquote"><p>
            <span class="inlinemediaobject"><img src="../../../../graphs/uniform_pdf.svg" align="middle"></span>

          </p></blockquote></div>
<p>
          Likewise for the CDF:
        </p>
<div class="blockquote"><blockquote class="blockquote"><p>
            <span class="inlinemediaobject"><img src="../../../../graphs/uniform_cdf.svg" align="middle"></span>

          </p></blockquote></div>
<h5>
<a name="math_toolkit.dist_ref.dists.uniform_dist.h0"></a>
          <span class="phrase"><a name="math_toolkit.dist_ref.dists.uniform_dist.member_functions"></a></span><a class="link" href="uniform_dist.html#math_toolkit.dist_ref.dists.uniform_dist.member_functions">Member
          Functions</a>
        </h5>
<pre class="programlisting"><span class="identifier">uniform_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">lower</span> <span class="special">=</span> <span class="number">0</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">upper</span> <span class="special">=</span> <span class="number">1</span><span class="special">);</span>
</pre>
<p>
          Constructs a <a href="http://en.wikipedia.org/wiki/uniform_distribution" target="_top">uniform
          distribution</a> with lower <span class="emphasis"><em>lower</em></span> (a) and upper
          <span class="emphasis"><em>upper</em></span> (b).
        </p>
<p>
          Requires that the <span class="emphasis"><em>lower</em></span> and <span class="emphasis"><em>upper</em></span>
          parameters are both finite; otherwise if infinity or NaN then calls <a class="link" href="../../error_handling.html#math_toolkit.error_handling.domain_error">domain_error</a>.
        </p>
<pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">lower</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
</pre>
<p>
          Returns the <span class="emphasis"><em>lower</em></span> parameter of this distribution.
        </p>
<pre class="programlisting"><span class="identifier">RealType</span> <span class="identifier">upper</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
</pre>
<p>
          Returns the <span class="emphasis"><em>upper</em></span> parameter of this distribution.
        </p>
<h5>
<a name="math_toolkit.dist_ref.dists.uniform_dist.h1"></a>
          <span class="phrase"><a name="math_toolkit.dist_ref.dists.uniform_dist.non_member_accessors"></a></span><a class="link" href="uniform_dist.html#math_toolkit.dist_ref.dists.uniform_dist.non_member_accessors">Non-member
          Accessors</a>
        </h5>
<p>
          All the <a class="link" href="../nmp.html" title="Non-Member Properties">usual non-member accessor
          functions</a> that are generic to all distributions are supported:
          <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.cdf">Cumulative Distribution Function</a>,
          <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.pdf">Probability Density Function</a>,
          <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.quantile">Quantile</a>, <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.hazard">Hazard Function</a>, <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.chf">Cumulative Hazard Function</a>,
          <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.mean">mean</a>, <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.median">median</a>,
          <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.mode">mode</a>, <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.variance">variance</a>,
          <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.sd">standard deviation</a>,
          <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.skewness">skewness</a>, <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.kurtosis">kurtosis</a>, <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.kurtosis_excess">kurtosis_excess</a>,
          <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.range">range</a> and <a class="link" href="../nmp.html#math_toolkit.dist_ref.nmp.support">support</a>.
        </p>
<p>
          The domain of the random variable is any finite value, but the supported
          range is only <span class="emphasis"><em>lower</em></span> &lt;= x &lt;= <span class="emphasis"><em>upper</em></span>.
        </p>
<h5>
<a name="math_toolkit.dist_ref.dists.uniform_dist.h2"></a>
          <span class="phrase"><a name="math_toolkit.dist_ref.dists.uniform_dist.accuracy"></a></span><a class="link" href="uniform_dist.html#math_toolkit.dist_ref.dists.uniform_dist.accuracy">Accuracy</a>
        </h5>
<p>
          The uniform distribution is implemented with simple arithmetic operators
          and so should have errors within an epsilon or two.
        </p>
<h5>
<a name="math_toolkit.dist_ref.dists.uniform_dist.h3"></a>
          <span class="phrase"><a name="math_toolkit.dist_ref.dists.uniform_dist.implementation"></a></span><a class="link" href="uniform_dist.html#math_toolkit.dist_ref.dists.uniform_dist.implementation">Implementation</a>
        </h5>
<p>
          In the following table a is the <span class="emphasis"><em>lower</em></span> parameter of
          the distribution, b is the <span class="emphasis"><em>upper</em></span> parameter, <span class="emphasis"><em>x</em></span>
          is the random variate, <span class="emphasis"><em>p</em></span> is the probability and <span class="emphasis"><em>q
          = 1-p</em></span>.
        </p>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th>
                  <p>
                    Function
                  </p>
                </th>
<th>
                  <p>
                    Implementation Notes
                  </p>
                </th>
</tr></thead>
<tbody>
<tr>
<td>
                  <p>
                    pdf
                  </p>
                </td>
<td>
                  <p>
                    Using the relation: pdf = 0 for x &lt; a, 1 / (b - a) for a &lt;=
                    x &lt;= b, 0 for x &gt; b
                  </p>
                </td>
</tr>
<tr>
<td>
                  <p>
                    cdf
                  </p>
                </td>
<td>
                  <p>
                    Using the relation: cdf = 0 for x &lt; a, (x - a) / (b - a) for
                    a &lt;= x &lt;= b, 1 for x &gt; b
                  </p>
                </td>
</tr>
<tr>
<td>
                  <p>
                    cdf complement
                  </p>
                </td>
<td>
                  <p>
                    Using the relation: q = 1 - p, (b - x) / (b - a)
                  </p>
                </td>
</tr>
<tr>
<td>
                  <p>
                    quantile
                  </p>
                </td>
<td>
                  <p>
                    Using the relation: x = p * (b - a) + a;
                  </p>
                </td>
</tr>
<tr>
<td>
                  <p>
                    quantile from the complement
                  </p>
                </td>
<td>
                  <p>
                    x = -q * (b - a) + b
                  </p>
                </td>
</tr>
<tr>
<td>
                  <p>
                    mean
                  </p>
                </td>
<td>
                  <p>
                    (a + b) / 2
                  </p>
                </td>
</tr>
<tr>
<td>
                  <p>
                    variance
                  </p>
                </td>
<td>
                  <p>
                    (b - a) <sup>2</sup> / 12
                  </p>
                </td>
</tr>
<tr>
<td>
                  <p>
                    mode
                  </p>
                </td>
<td>
                  <p>
                    any value in [a, b] but a is chosen. (Would NaN be better?)
                  </p>
                </td>
</tr>
<tr>
<td>
                  <p>
                    skewness
                  </p>
                </td>
<td>
                  <p>
                    0
                  </p>
                </td>
</tr>
<tr>
<td>
                  <p>
                    kurtosis excess
                  </p>
                </td>
<td>
                  <p>
                    -6/5 = -1.2 exactly. (kurtosis - 3)
                  </p>
                </td>
</tr>
<tr>
<td>
                  <p>
                    kurtosis
                  </p>
                </td>
<td>
                  <p>
                    9/5
                  </p>
                </td>
</tr>
</tbody>
</table></div>
<h5>
<a name="math_toolkit.dist_ref.dists.uniform_dist.h4"></a>
          <span class="phrase"><a name="math_toolkit.dist_ref.dists.uniform_dist.references"></a></span><a class="link" href="uniform_dist.html#math_toolkit.dist_ref.dists.uniform_dist.references">References</a>
        </h5>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
              <a href="http://en.wikipedia.org/wiki/Uniform_distribution_%28continuous%29" target="_top">Wikipedia
              continuous uniform distribution</a>
            </li>
<li class="listitem">
              <a href="http://mathworld.wolfram.com/UniformDistribution.html" target="_top">Weisstein,
              Weisstein, Eric W. "Uniform Distribution." From MathWorld--A
              Wolfram Web Resource.</a>
            </li>
<li class="listitem">
              <a href="http://www.itl.nist.gov/div898/handbook/eda/section3/eda3662.htm" target="_top">http://www.itl.nist.gov/div898/handbook/eda/section3/eda3662.htm</a>
            </li>
</ul></div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2006-2021 Nikhar Agrawal, Anton Bikineev, Matthew Borland,
      Paul A. Bristow, Marco Guazzone, Christopher Kormanyos, Hubert Holin, Bruno
      Lalande, John Maddock, Evan Miller, Jeremy Murphy, Matthew Pulver, Johan Råde,
      Gautam Sewani, Benjamin Sobotta, Nicholas Thompson, Thijs van den Berg, Daryle
      Walker and Xiaogang Zhang<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="triangular_dist.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../dists.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="weibull_dist.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
